package com.boyaa.shells.tool 
{
	import com.adobe.utils.IntUtil;
	import com.boyaa.shells.GlobalConfig;
	import com.boyaa.shells.lang.LangManager;
	/**
	 * ...
	 * @author zc
	 */
	public class AnalysisData
	{
		
		public function AnalysisData() 
		{
			
		}
		
		/** 得到日期，like XXXX-XX-XX or XXXX:XX:XX */
		public static function getDataString(sign:String, millisecond:Number):String {
			var now:Date = new Date();
			now.setTime( millisecond * 1000);
			if (GlobalConfig.lanVersion == 2)
				return now.date + sign + (now.month + 1)  + sign + now.fullYear;
			else
				return now.fullYear + sign + (now.month + 1)  + sign + now.date;
		}
		
		public static function getDaySecString(date1:Number,date2:Number):Array
		{
			var d:int = (date2 - date1);
			//trace(new Date(date2) + "" + new Date(date1));
			var dy:int = d / (24 * 3600);
			var hour:int = (d - dy *24 * 3600)/3600;
			var minu:int = (d - dy * 24 * 3600 - hour * 3600)/60;
			var second:int = (d - dy * 24 * 3600 - hour * 3600 - minu*60);
			return [dy+"",hour+"",minu+"",second+""];
		}
		
		public static function getAllDataString(sign:String,millisecond:Number):String {
			var now:Date = new Date();
			now.setTime( millisecond * 1000);
			var str:String = "";
			if(now.minutes <10)
				str= now.hours + ":0" + now.minutes;
			else
				str= now.hours + ":" + now.minutes;
			return str;
		}
		
		//得到年
		public static function getYear(millisecond:Number):String {
			var now:Date = new Date();
			now.setTime( millisecond * 1000);
			return now.fullYear+"";
		}
		
		//得到月
		public static function getMonth(millisecond:Number):String {
			var now:Date = new Date();
			now.setTime( millisecond * 1000);
			return (now.month+1)+"";
		}
		
		//得到日
		public static function getDate(millisecond:Number):String {
			var now:Date = new Date();
			now.setTime( millisecond * 1000);
			return now.date+"";
		}
		
		//得到时
		public static function getHour(millisecond:Number):String {
			var now:Date = new Date();
			now.setTime( millisecond * 1000);
			return now.hours+"";
		}
		
		//得到分
		public static function getMinute(millisecond:Number):String {
			var now:Date = new Date();
			now.setTime( millisecond * 1000);
			return now.minutes+"";
		}
		
		//得到秒
		public static function getSecond(millisecond:Number):String {
			var now:Date = new Date();
			now.setTime( millisecond * 1000);
			return now.seconds+"";
		}
		
		//得到相差多少天
		public static function dayDefference(date1:Number, date2:Number):Number 
		{
			var d:int = (date2 - date1) / (3600*24);
			return d;
		}
		
		//得到相差多少小時
		public static function hourDefference(date1:Number, date2:Number):Number 
		{
			var d:int = (date2 - date1) / 3600;
			return d;
		}
		
			//得到相差多少分钟
		public static function minuteDefference(date1:Number, date2:Number):Number 
		{
			var d:int = (date2 - date1) / 60;
			return d;
		}
		
			//得到相差多少秒
		public static function secondsDefference(date1:Number, date2:Number):Number 
		{
			var d:int = (date2 - date1);
			return d;
		}
		
		public static function timedifference(date1:Number, date2:Number):Number
		{
			//var d:int = ((date2 - date1) / 3600)-1;
			var returnNum:Number = 0;
			var now1:Date = new Date();
			now1.setTime( date1 * 1000);
			
			var now2:Date = new Date();
			now2.setTime( date2 * 1000);
			
			var month1:Number = now1.month + 1;
			//var year1:Number = now1.fullYear;
			var day1:Number = now1.date;
			
			var month2:Number = now2.month + 1;
			var year2:Number = now2.fullYear;
			var day2:Number = now2.date;
			
			var runnian:Number = 0;
			//润年
			if ((year2 % 4 ==0 && year2 %100 !=0) || year2 % 400 ==0 )
			{
				
				if (month2 > 2 && month1 <= 2) 
				{
					runnian = runnian - 1 ;
				}
			}
			else
			{
				if (month2 > 2 && month1 <= 2) 
				{
					runnian = runnian - 2 ;
				}
			}
			//月大
			if (month1 < month2) 
			{
				switch (month1)
				{
					case 1:
					case 3:
					case 5:
					case 7:
					case 8:
					case 10:
					case 12:
						runnian += 1; 
				}
			}
			
			//如果不是同一年的计算
			if (month1 > month2)
				month2 += 12;
			var month:Number = month2 - month1;
			var day:Number = day2 - day1;
			returnNum = month * 30 + day + runnian;
			return returnNum;
		}
		
		public static function bettwenThisTime(startTime:Number,endTime:Number,thisTime:Number):Boolean
		{
			var flag:Boolean = true;
			if (hourDefference(startTime, thisTime) < 0)
			{
				flag = false;
			}
			else if (hourDefference(thisTime, endTime) < 0)
			{
				flag = false;
			}
			return flag;
		}
		
		/**
		 * 计算离线时间
		 * @param	time
		 */
		public static function getOfflineTime(date1:Number, date2:Number):String
		{
			var hour1:int = Math.ceil(date1 / 3600);//date1是PHP传过来的秒数
			var hour2:int = Math.ceil(date2 / 1000 / 3600);//本地时间按毫秒算
			var hours:int = Math.abs(hour2 - hour1);
			if (hours < 24)									// 不足1天的显示小时
			{
				return hours + LangManager.getLang.getLangByStr("hour");
			}
			else if (hours > 24 && hours < 168)				// 不足1周的显示天数
			{
				return Math.ceil(hours / 24) + LangManager.getLang.getLangByStr("day");
			}
			else if (hours > 168 && hours < 720)			// 大于1周，不足1个月，显示周数
			{
				return Math.ceil(hours / (24 * 7)) + LangManager.getLang.getLangByStr("week");
			}
			else if (hours > 720 && hours < 4320)			// 大于1个月，小于6个月，显示月数
			{
				return Math.ceil(hours / (24 * 30)) + LangManager.getLang.getLangByStr("month");
			}
			else if (hours > 4320)							// 大于6个月，显示很久
			{
				return LangManager.getLang.getLangByStr("forlong");
			}
			return "";
		}
	}

}